/*
 * @Description  : 
 * @Date         : 2021-05-12 16:35:33
 * @Author       : 保锋
 * @LastEditTime : 2021-05-25 11:11:33
 * @LastEditors  : 保锋
 * @FilePath     : \caiying_flutter\lib\model\user_real_data_reault.dart
 */
import 'package:flutter/material.dart';
import 'package:yinshui_caiying/utils/colors.dart';

class UserRealDataResultModel {
  late int code;
  late String message;
  late Content content;

  UserRealDataResultModel(
      {required this.code, required this.message, required this.content});

  UserRealDataResultModel.fromJson(Map<String, dynamic> json) {
    code = json['code'];
    message = json['message'];
    content = (json['content'] != null
        ? new Content.fromJson(json['content'])
        : null)!;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['code'] = this.code;
    data['message'] = this.message;
    if (this.content != null) {
      data['content'] = this.content.toJson();
    }
    return data;
  }
}

class Content {
  late int total;
  late int page;
  late int perPage;
  late UserRealDataModel data;

  Content(
      {required this.total,
      required this.page,
      required this.perPage,
      required this.data});

  Content.fromJson(Map<String, dynamic> json) {
    total = json['total'];
    page = json['page'];
    perPage = json['per_page'];
    data = (json['data'] != null
        ? new UserRealDataModel.fromJson(json['data'])
        : null)!;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['total'] = this.total;
    data['page'] = this.page;
    data['per_page'] = this.perPage;
    if (this.data != null) {
      data['data'] = this.data.toJson();
    }
    return data;
  }
}

///实时数据模型
class UserRealDataModel {
  ///累计流量
  late String? totalFlow;

  ///信号强度
  late String? signal;

  ///设备状态（onLine 在线,offLine 离线,sleep 休眠）
  late String status;

  ///电池电压
  late String? voltage;

  ///开关状态(0开1关)
  late String switchStatus;

  ///通讯时间
  late String time;

  UserRealDataModel(
      {required this.totalFlow,
      required this.signal,
      required this.status,
      required this.voltage,
      required this.switchStatus,
      required this.time});

  ///获取设备状态名称
  String getStatusName() {
    switch (this.status) {
      case 'onLine':
        return '在线';
      case 'offLine':
        return '离线';
      case 'sleep':
        return '休眠';
      default:
        return '-';
    }
  }

  ///获取设备状态颜色
  Color getStatusColor() {
    switch (this.status) {
      case 'onLine':
        return MyColors.main;
      case 'offLine':
        return Colors.red;
      case 'sleep':
        return Colors.orange;
      default:
        return Colors.red;
    }
  }

  ///获取开关状态名字
  String getSwitchStatusName() {
    switch (this.switchStatus) {
      case '0':
        return '开';
      case '1':
        return '关';

      default:
        return '-';
    }
  }

  ///获取开关状态颜色
  Color getSwitchStatusColor() {
    switch (this.switchStatus) {
      case '0':
        return MyColors.main;
      case '1':
        return Colors.red;

      default:
        return Colors.red;
    }
  }

  UserRealDataModel.fromJson(Map<String, dynamic> json) {
    totalFlow = json['total_flow'];
    signal = json['signal'];
    status = json['status_status'];
    voltage = json['voltage'];
    switchStatus = json['switch'];
    time = json['time'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['total_flow'] = this.totalFlow;
    data['signal'] = this.signal;
    data['status'] = this.status;
    data['voltage'] = this.voltage;
    data['status_status'] = this.switchStatus;
    return data;
  }
}
